home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig18_03.jar / Ch18 / Fig18_03 / Fig18_03.cpp < prev    next >
C/C++ Source or Header  |  1997-11-10  |  621b  |  26 lines

  1. // Fig. 18.3: fig18_03.cpp
  2. // Using command-line arguments
  3. #include <iostream.h>
  4. #include <fstream.h>
  5.  
  6. int main( int argc, char *argv[] )
  7. {
  8.    if ( argc != 3 )
  9.       cout << "Usage: copy infile outfile" << endl;
  10.    else {
  11.       ifstream inFile( argv[ 1 ], ios::in );
  12.       if ( !inFile )
  13.          cout << argv[ 1 ] << " could not be opened" << endl;
  14.  
  15.       ofstream outFile( argv[ 2 ], ios::out );
  16.       if ( !outFile )
  17.          cout << argv[ 2 ] << " could not be opened" << endl;
  18.  
  19.       while ( !inFile.eof() )
  20.          outFile.put( static_cast< char >( inFile.get() ) );
  21.    }
  22.  
  23.    return 0;
  24. }
  25.  
  26.